#include<iostream>
#include<algorithm>
using namespace std;
const int M = 2e5 + 10, N = 5e3 + 10;
int p[N];
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
struct Edge
{
	int a, b, w;
}edge[M];
int n, m;
int cmp(Edge a, Edge b)
{
	return a.w < b.w;
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		p[i] = i;
	}
	for (int i = 0; i < m; i++) {
		int a, b, w;
		scanf("%d%d%d", &a, &b, &w);
		edge[i] = { a,b,w };
	}
	sort(edge, edge + m, cmp);
	int cnt = 0;
	int ans = 0;
	for (int i = 0; i < m; i++) {
		int a = find(edge[i].a);
		int b = find(edge[i].b);
		int w = edge[i].w;
		if (a != b) {
			p[a] = b;
			cnt++;
			ans += w;
		}
	}
	if (cnt < n - 1) {
		cout << "orz" << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}